// 反转链表
/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
 var reverseList = function(head) {
    /*let arr = [];
    let link=head;
    while(link){
        arr.push(link.val);
        link=link.next;
    }
    arr=arr.reverse();
    let n=head;
    for(let c of arr){
        n.val=c;
        n=n.next
    }
  return head;*/
  /*if(head==null||head.next==null) return head;
      let last = reverseList(head.next);
     head.next.next=head;
      head.next=null
  return last;*/
  let pre = null;
  let curr = head;
  while(curr){
     let next = curr.next;
     curr.next=pre;
     pre=curr;
     curr=next;
  }
  return pre;
  }